package com.crm.biz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.annotation.SystemServiceLog;
import com.crm.model.BizActivityCode;
import com.crm.service.BizActivityCodeService;
import com.crm.util.AopConfig;
import com.crm.util.JsonUtil;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

@Controller
@RequestMapping("/bizActivityCode")
public class BizActivityCodeController {
	
	@Autowired
	private BizActivityCodeService bizActivityCodeService;
	
	
	@RequestMapping("/index")
	public String index(){
		
		return "";
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public void getAll(HttpServletResponse response,HttpServletRequest request, Page<BizActivityCode> page, BizActivityCode t){
		
		Page<BizActivityCode> list = (Page<BizActivityCode>) bizActivityCodeService.selectAll(page, t);
		
		ResponseUtil.resultPage(response,request,list);
	}
	
	@RequestMapping("/addNewRecord")
	@ResponseBody
	public Map<String, Object> addNewRecord(BizActivityCode record){
		
		Map<String, Object> map = new HashMap<>();
		
		bizActivityCodeService.insert(record);
		
		map.put("status", "success");
		map.put("msg", "新增成功！");
		
		return map;
	}
	
	@RequestMapping("/updateRecord")
	@ResponseBody
	public Map<String, Object> updateRecord(BizActivityCode record){
		
		Map<String, Object> map = new HashMap<>();
		
		bizActivityCodeService.updateByPrimaryKey(record);
		
		map.put("status", "success");
		map.put("msg", "修改成功！");
		
		return map;
	}
	
	@RequestMapping("/load")
	@ResponseBody
	public void load(HttpServletResponse response,HttpServletRequest request, Page<BizActivityCode> page, BizActivityCode t){
		Page<BizActivityCode> list = (Page<BizActivityCode>) bizActivityCodeService.selectAll(page, t);
		ResponseUtil.resultPage(response,request,list);
	
	}
	
	/**
	 * 
	 * @Description : 控制台获取优惠吗信息
	 * @author zealot
	 * @param @param response
	 * @param @param request
	 * @param @param t
	 * @return void
	 * @version 创建时间 : 2016年12月12日 下午7:00:25
	 * @thorws
	 */
	@RequestMapping("/loadCode")
	@ResponseBody
	public void loadCode(HttpServletResponse response,HttpServletRequest request,  BizActivityCode t){
		 List<BizActivityCode> list = bizActivityCodeService.selectByUs(t);
		 ResponseUtil.result(response, JsonUtil.toJsonStr(list));
	}
	
	/**
	 * 
	 * @Description : TODO
	 * @author zealot
	 * @param @param record
	 * @param @return
	 * @return Map<String,Object>
	 * @version 创建时间 : 2016年12月13日 上午10:38:33
	 * @thorws
	 */
	@RequestMapping("/ajaxUpdateRecord")
	@SystemServiceLog(description=AopConfig.WORKBENCHACTIVITYCODE+AopConfig.USE,type=AopConfig.USE)
	@ResponseBody
	public Map<String, Object> ajaxUpdateRecord(BizActivityCode record){
		
		Map<String, Object> map = new HashMap<>();
		
		bizActivityCodeService.ajaxUpdateRecord(record);
		
		map.put("status", "success");
		map.put("msg", "修改成功！");
		
		return map;
	}
}
